package com.simsuni.concept.ext;

import java.util.HashMap;

import com.simsuni.concept.SimEntity;
import com.simsuni.concept.SimScheduler;
import com.simsuni.concept.SimServiceEntity;
import com.simsuni.concept.SimModel;
import com.simsuni.concept.SimProcess;
import com.simsuni.concept.io.EntityConsumer;
import com.simsuni.concept.io.EntityProducer;

public class SimWorld {
	
	public static void Main(String args[]){
		
		SimModel model = loadModel();
		SimScheduler scheduler = new SimScheduler(model);
		scheduler.run();
	}
	private static SimModel loadModel(){
		
		SimModel model = new SimModel("Bank");
		
		SimEntity entrance = new EntityProducer("Entrance");
		
		SimList queue1 = new SimQueue();
		SimServiceEntity server1 = new SimServiceEntity("Server1",queue1);
		SimServiceEntity server2 = new SimServiceEntity("Server2",queue1);
		SimEntity group1 = new SimEntity("Group1");
		group1.addEntity(server1);
		group1.addEntity(server2);
		
		
		SimEntity group2 = new SimEntity("Group2");
		SimList queue2 = new SimQueue();
		SimServiceEntity server3 = new SimServiceEntity("Server3",queue2);
		SimServiceEntity server4 = new SimServiceEntity("Server4",queue2);
		group2.addEntity(server3);
		group2.addEntity(server4);
		
		
		SimServiceEntity server5 = new SimServiceEntity("Server5",new SimQueue());
		SimServiceEntity server6 = new SimServiceEntity("Server6",new SimQueue());
		SimServiceEntity server7 = new SimServiceEntity("Server7",new SimQueue());
		
		
		
		
		SimEntity exit = new EntityConsumer("Exit");
		
		model.addEntity(entrance);
		model.addEntity(group1);
		model.addEntity(group2);
		model.addEntity(server5);
		model.addEntity(server6);
		model.addEntity(server7);
		model.addEntity(exit);
		
		
		return model;
	}
	public SimProcess makeProcess(SimModel model){
		
		final SimEntity entrance = model.getEntity("Entrance");
		final SimEntity group1 = model.getEntity("Group1");
		final SimEntity group2 = model.getEntity("Group2");
		final SimEntity server5 = model.getEntity("Server5");
		final SimEntity server6 = model.getEntity("Server6");
		final SimEntity server7 = model.getEntity("Server7");
		final SimEntity exit = model.getEntity("Exit");
		
		
		final SimConnector connEntrance = new SimConnector(entrance,group1);
		final SimConnector connGroup1 = new SimConnector(group1,group2){

			@Override
			public SimEntity getNextService(SimEntity entity) {
				
				return null;
			}
			
		};
		connGroup1.addTarget(server5);
		final SimConnector connGroup2 = new SimConnector(group2,server5);
		connGroup2.addTarget(server6);
		final SimConnector connServer6 = new SimConnector(server6,server7);
		final SimConnector connServer5 = new SimConnector(server5,exit);
		final SimConnector connServer7 = new SimConnector(server7,exit);
		
		final HashMap<String, SimConnector> connMap = new HashMap<String, SimConnector>();
		
		connMap.put(connEntrance.getName(), connEntrance);
		connMap.put(connGroup1.getName(), connGroup1);
		connMap.put(connGroup2.getName(), connGroup2);
		connMap.put(connServer6.getName(), connServer6);
		connMap.put(connServer5.getName(), connServer5);
		connMap.put(connServer7.getName(), connServer7);
		
		SimProcess process = new SimProcess(model.getName(),entrance){
			public SimEntity getNextEntity(SimEntity foreEntity){
//				return connMap.get(foreEntity.getName()).getTarget();
				return null;//TODO JAKE
			}
		};
		return process;
	}
}
